package com.tuling.spring.scan;

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ClassPathBeanDefinitionScanner;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

public class MyMapperScanRegistar implements ImportBeanDefinitionRegistrar {
    @Override
    public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionRegistry registry) {
        Map<String, Object> attributes = metadata.getAnnotationAttributes(MyMapperScan.class.getName());
        String value = attributes.get("value").toString();
        // 进行扫描
        ClassPathBeanDefinitionScanner scanner = new MyClassPathBeanDefinitionScanner(registry);
        // 忽略扫描 BeanDefinition 的判断
        scanner.addIncludeFilter((metadataReader, metadataReaderFactory) -> true);
        scanner.scan(value);
    }
}
